<template>
	<view class="question-detail-page">
		<view class="question-part">
			<view style="padding: 20upx;">
				<text style="font-size: 36upx;">{{questionObj.content}}</text>
				<view class="d-flex a-center" style="font-size: 26upx;color: #999999;">
					<image :src="defaultSrc" style="height: 50upx;width: 50upx;margin-right: 8upx;" mode=""></image>
					<text style="font-size: 24upx;">{{questionObj.userName}} 提问于{{questionObj.date}}</text>
				</view>
			</view>
			<view class="question-detail-content">
				<view v-for="(qitem,qindex) in questionObj.questionList" :key="qindex" style="margin-bottom: 20upx;">
					<view class="d-flex a-center">
						<uni-tag text="答" size="small" type="success" style="margin-right: 20upx;"></uni-tag>
						<image :src="defaultSrc" style="height: 50upx;width: 50upx;margin-right: 8upx;" mode=""></image>
						<text style="color: #2A2A2A;font-size: 32upx;">{{qitem.userName}}</text>
					</view>
					<view>
						<text style="color: #2A2A2A;line-height: 46upx;">{{qitem.content}}</text>
					</view>
					<view class="d-flex j-sb">
						<text style="color: #999999;">{{qitem.date}}</text>
						<text class="iconfont icon-pinglun1" style="color: #999999;"></text>
					</view>
				</view>
			</view>
		</view>
		<view v-if="commentVisible" class="comment-area d-flex a-center border-top j-sb" :style="'bottom:' + fixedBottom + 'px;'">
			<input class="comment-input" ref="commentNode" v-model="questionContent" @focus="onFocusEvent" type="text">
			<view class="comment-btn" @tap="saveCommentInfo(questionObj)">
				<text>发表</text>
			</view>
		</view>
	</view>
</template>

<script>
	import uniTag from "@/components/uni-ui/uni-tag/uni-tag.vue";
	import api from '@/common/lib/request.js';
	export default {
		data() {
			return {
				questionObj: {},
				contentId: "",
				fixedBottom: 0,
				questionContent: "",
				commentVisible: true,
				defaultSrc: "../../../../static/images/estate/author.png"
			}
		},
		components: {
			uniTag
		},
		onLoad(options) {
			this.contentId = options.contentId;
			this.questionObj = JSON.parse(decodeURIComponent(options.questions));
			uni.setNavigationBarTitle({
				'title': "问答详情"
			})
		},
		methods: {
			onFocusEvent(event){
				console.log(event)
				// this.commentVisible = false;
				// this.fixedBottom = event.detail.height;
			},
			// 保存评论信息
			saveCommentInfo(questionObj) {
				let _this = this;
				api.request({
						url: '/lpxx/question/save',
						data: {
							contentId: this.contentId,
							parentId: questionObj.id,
							type: 2,
							content: this.questionContent
						}
					})
					.then(response => {
						console.log(response)
						this.questionObj = response;
						this.questionContent = "";
						this.fixedBottom = 0;
					})
					.catch(err => {
						console.log(err);
					});
			}
		}
	}
</script>

<style>
	.question-detail-page {
		background-color: #F2F2F2;
		height: 100%;
	}

	.question-part {
		margin: 0 20upx;
		background: #f0e8e8;
	}

	.question-detail-content {
		background-color: #FFFFFF;
		border-radius: 20upx;
		padding: 20upx;
		margin-top: 20upx;
	}

	.comment-area {
		position: fixed;
		bottom: 0;
		background-color: white;
		width: 670upx;
		padding: 0 40upx;
		height: 90upx;
		z-index: 999;
	}

	.comment-input {
		background-color: #eee;
		height: 72upx;
		border-radius: 36upx;
		width: 480upx;
		text-indent: 36upx;
		font-size: 32upx;
	}

	.comment-btn {
		width: 160upx;
		height: 72upx;
		border-radius: 36upx;
		background-color: orange;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>
